#! /usr/bin/env python
#coding=utf-8

import sys

class CliParser(object):
    "用户操作命令（UOC）分析基类"
    uoclevel = 'normal'
    
    def __init__(self, uocname, uocparams, user):
        self.uocname = uocname
        self.uocparams = uocparams
        # 包含认证，日志，配置信息的user对象
        self.user = user

    def uoc_parse(self):
        "执行UOC分析"
        if self.user.level == None:
            self.user.log.writeLog('uoc level error, unauthenticate.', 'error')
            return None
            
        if self.user.level == 'normal' and self.uoclevel == 'admin':
            self.user.log.writeLog('uoc level error', 'error')
            return None

        if len(self.uocparams) > 0:
            self.direct_parse()
        else:
            self.interact_parse()
            
    def direct_parse(self):
        "直接型命令分析"
        pass
    
    def interact_parse(self):
        "交互性命令分析"
        pass
    
    def get_input(self, info):
        print info
        input = sys.stdin.readline()
        if not input:
            self.user.log.writeLog('user cancel add uoc.', 'info')
            return None
        else:
            return input
    